package com.meko.tms.core.access;

import com.alibaba.fastjson.JSON;
import com.meko.tms.core.service.ObtainDataService;
import com.meko.tms.core.service.DataSolutionService;
import com.meko.tms.core.service.IncrementalAdditionDataService;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class AccessData extends AbstractAccessData{

    final DataSolutionService dataSolutionService;
    final IncrementalAdditionDataService incrementalAdditionDataService;

    public AccessData(ObtainDataService obtainDataService,
                      DataSolutionService dataSolutionService, IncrementalAdditionDataService incrementalAdditionDataService) {
        super(obtainDataService);
        this.dataSolutionService = dataSolutionService;
        this.incrementalAdditionDataService = incrementalAdditionDataService;
    }



    @Override
    protected <T> void solutionData(List<T> objectList) {
        try {
            if (objectList == null) {
                log.info("暂未获取到数据");
//                return;
            }
            dataSolutionService.solutionData(objectList);
        }catch (Exception e){
            log.info("处理数据失败：", JSON.toJSONString(objectList));
        }
    }

    @Override
    protected <T> boolean incrementalAdditionData(List<T> list) {
        try {
            return incrementalAdditionDataService.incrementalAdditionData(list);
        }catch (Exception e){
            return false;
        }

    }
}
